package com.le.tester.book.concurrentjavafight.l6_2_4;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * createTime：2022/10/19 14:06
 * description：支持关闭操作的WebServer
 */
public class LifecycleWebServer {

    private final ExecutorService exec = Executors.newCachedThreadPool();

    public void start() throws IOException {
        ServerSocket socket = new ServerSocket(80);

        while (!exec.isShutdown()) {
            Socket conn = socket.accept();
            exec.execute(new Runnable() {
                @Override
                public void run() {
                    handleRequest(conn);
                }
            });
        }
    }

    private void handleRequest(Socket conn) {

    }
}
